package com.hp.team.bookstore.dbaccess.dao.order;

import java.util.List;

import org.hibernate.criterion.Example;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.hp.team.bookstore.dbaccess.dao.GenericHibernateDAO;
import com.hp.team.bookstore.model.order.SalesOrder;

@Repository
public class SalesOrderHibernateDAO extends GenericHibernateDAO<SalesOrder, Long> {

//	public List<SalesOrder> findByExample(SalesOrder example) {
//		List<String> excludedProperties = new ArrayList<String>();
//
//		if (example.getShippingFees() == 0) {
//			excludedProperties.add("shippingFees");
//		}
//
//		if (example.getSubTotalPrice() == 0) {
//			excludedProperties.add("subTotalPrice");
//		}
//
//		if (example.getGrandTotalPrice() == 0) {
//			excludedProperties.add("grandTotalPrice");
//		}
//
//		if (example.getTaxes() == 0) {
//			excludedProperties.add("taxes");
//		}
//
//		return findByExample(example, excludedProperties.toArray(new String[excludedProperties.size()]));
//	}
	
	@SuppressWarnings("unchecked")
	public List<SalesOrder> findByCreator(SalesOrder exampleOrder, long creatorId){
		Example example = getExample(exampleOrder);

		return (List<SalesOrder>) getSession()
				.createCriteria(SalesOrder.class).add(example)
				.createCriteria("creator").add(Restrictions.eq("id", creatorId))
				.list();
	}

}
